<?php

/**
 * This is the model class for table "pupil".
 *
 * The followings are the available columns in table 'pupil':
 * @property integer $id
 * @property string $ph_od
 * @property string $ph_os
 * @property string $sc_od
 * @property string $sc_os
 * @property string $papd_od
 * @property string $papd_os
 * @property integer $rx_id
 * @property integer $personalinfo_id
 *
 * The followings are the available model relations:
 * @property Rx $rx
 * @property PersonalInformation $personalinfo
 */
class Pupil extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Pupil the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'pupil';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('rx_id, personalinfo_id', 'numerical', 'integerOnly'=>true),
			array('ph_od, ph_os, sc_od, sc_os, papd_od, papd_os', 'length', 'max'=>5),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, ph_od, ph_os, sc_od, sc_os, papd_od, papd_os, rx_id, personalinfo_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'rx' => array(self::BELONGS_TO, 'Rx', 'rx_id'),
			'personalinfo' => array(self::BELONGS_TO, 'PersonalInformation', 'personalinfo_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'ph_od' => 'Ph Od',
			'ph_os' => 'Ph Os',
			'sc_od' => 'Sc Od',
			'sc_os' => 'Sc Os',
			'papd_od' => 'Papd Od',
			'papd_os' => 'Papd Os',
			'rx_id' => 'Rx',
			'personalinfo_id' => 'Personalinfo',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('ph_od',$this->ph_od,true);
		$criteria->compare('ph_os',$this->ph_os,true);
		$criteria->compare('sc_od',$this->sc_od,true);
		$criteria->compare('sc_os',$this->sc_os,true);
		$criteria->compare('papd_od',$this->papd_od,true);
		$criteria->compare('papd_os',$this->papd_os,true);
		$criteria->compare('rx_id',$this->rx_id);
		$criteria->compare('personalinfo_id',$this->personalinfo_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}